<template>
    <div class="pageContainer">
        <div class="searchWarp">
            <template v-for="condition in listCondition">
                <CCondition :condition="condition"></CCondition>
            </template>
            <div class="schLine">
                <CBtn @click="search(1)">查询</CBtn>
            </div>
        </div>
        <div class="treeTable">
            <div style="flex:1;">
                <div class="btnWarp">
                    <CBtn @click="showEdit">新增</CBtn>
                    <CBtn @click="doBatchDel()">批量删除</CBtn>
                </div>
                <CPageTable :data="tableData" :curPage="paging.curPage" :total="paging.total" 
                    @changeSelect="changeSelect"
                    @changeSize="changeSize" @changePage="search">
                    <template slot-scope="scope">
                        <CBtn type="text" @click="showVote(scope.row)">授予角色</CBtn>
                        <CBtn type="text" @click="showEdit(scope.row)">修改</CBtn>
                        <CBtn v-if="scope.row.del_is == 'Y'" type="text" @click="doDel(scope.row)">删除</CBtn>
                    </template>
                </CPageTable>
            </div>
        </div>

        <CDailog title="新增/编辑" :isShow="isShowEdit" @close="isShowEdit = false" @enter="doSave">
            <el-form :inline="true">
                <CText form v-model="mm.account" title="帐号" field="account"></CText>
                <CText form v-model="mm.nickName" title="呢称" field="nickName"></CText>
                <CText form v-model="mm.realName" title="真实姓名" field="realName"></CText>
                <CText form v-model="mm.mobile" title="手机号" field="mobile"></CText>
                <CSelect form v-model="mm.fkOrgId" title="公司" field="fkOrgId" opType="opCompany"></CSelect>
                <CSelect form v-model="mm.fkDeptId" title="部门" field="fkDeptId" opType="opDept"></CSelect>
                <CSelect form v-model="mm.val" title="性别" field="sex" opType="sex"></CSelect>
            </el-form>
        </CDailog>

        <CDailog title="授予角色" :isShow="isShowVote" @close="isShowVote = false" @enter="doVoteRole">
            <div class="roleWarp">
                <el-checkbox-group v-model="selRole">
                    <el-checkbox v-for="item in listRole" :label="item.id" :value="item.id">
                        {{item.name}}
                    </el-checkbox>
                </el-checkbox-group>
            </div>
        </CDailog>
    </div>
</template>

<script>
import pagingMixin from '@/mixin/pagingMixin'
export default {
    mixins: [pagingMixin],
    data() {
        return {
            isShowVote: false,
            model: "ums",
            table: "UmsAdmin",
            listRole: [],
            selRole: [],
            curAdminId: ""
            
        }
    },
    created() {
        this.templateId = "044fa205-e9c1-4fb1-8063-b4f10a65e31b";
        
        //取得查询条件
        this.$sys.getPageConditions({id: this.templateId}).then(res => {
            this.listCondition = res.data;
        })
        //查询表格数据
        this.search(1);
    },
    methods: {
        doDel(row) {
            this.$u.confirm().then(res => {
                this.$sys.logicDel(this.model, this.table, {id: row.id}).then(res => {
                    if (200 == res.code) {
                        this.$message.success("删除成功")
                        this.search();
                    } else {
                        this.$messgae.error("删除失败")
                    }
                })
            }).catch(e => {
                console.log(e);
                this.$message.info("取消删除")
            })
        },
        doVoteRole() {
            this.$ums.saveVoteRole({
                adminId:this.curAdminId,
                listRoleId: this.selRole
            }).then(res => {
                this.$u.showResultMsg(res);
                this.isShowVote = false;
            })
        },
        showVote(row) {
            
            this.$ums.getAllVoteRole({id: row.id}).then(res => {
                this.listRole = res.data.listRole;
                this.selRole = res.data.listAdminRole.map(item => item.fkRoleId);
                this.curAdminId = row.id;
                this.isShowVote = true;
            })
        }
    }
}
</script>

<style lang="scss" scoped>
.roleWarp {
    display: flex;
    flex-wrap: wrap;
}
</style>